package servlet;

import service.impl.StudentServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(urlPatterns = "/Educational/student/addstudents")
public class Addstu extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String stuname = req.getParameter("stuname");
        String stuno = req.getParameter("stuno");
        String sex = req.getParameter("sex");
        String email = req.getParameter("email");
        String gid = req.getParameter("gid");
        String registered = req.getParameter("registered");
        String politics = req.getParameter("politics");
        String address = req.getParameter("address");
        String phone = req.getParameter("phone");
        String idnumber = req.getParameter("idnumber");
        String introduction = req.getParameter("introduction");
        String profession = req.getParameter("profession");
        StudentServiceimpl studentServiceimpl = new StudentServiceimpl();
        int i = studentServiceimpl.addstu(stuname, stuno, address, email, phone, idnumber, politics, registered,
                profession, introduction, Integer.parseInt(gid), Integer.parseInt(sex));
        if (i!=0){
            resp.sendRedirect("/Educational/student/getstudents");
        }else {
            req.getRequestDispatcher("Educational/student/getgradelist").forward(req,resp);
        }


    }
}
